﻿var btnSearchControl;
var txtSearchControl;

//results
var lblTrackingNrControl;
var lblStateControl;
var lblNoResultsControl;
lblState

$(document).ready(function () {
    var btnSearchControl = $("#btnSearch")[0];
    var txtSearchControl = $("#txtSearch")[0];

    //results
    lblTrackingNrControl = $("#lblTrackingNr")[0];
    lblStateControl = $("#lblState")[0];
    lblNoResultsControl = $("#lblNoResults")[0];
    $(lblNoResultsControl).hide();

    //link events
    btnSearchControl.onclick = function () {
        var searchText = txtSearchControl.value;
        performSearch(searchText);
    };

});
function performSearch(trackingNr) {
    var jsonRequest = '{ "trackingNumber":"' + trackingNr + '"}';
    $.ajax({
        type: "GET",
        url: "/Shipment/Search?trackingNumber=" + trackingNr,
        //data: jsonRequest,
        datatype: "json",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            if (result != "") {
                $(lblNoResultsControl).hide();
                $(lblTrackingNrControl).text(result.TrackingNumber);
                $(lblStateControl).text(result.State);
            }
            else {
                $(lblNoResultsControl).show();

            }
        },
        error: function (x, e, m) {
            alert(x + " " + e);
        }
    }
        );
}

